package com.hlhj.funlike_business.activity.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hlhj.funlike_business.R;
import com.hlhj.funlike_business.bean.FoodDetailBean;

import java.util.List;

public class SpecificationsAdp extends RecyclerView.Adapter<SpecificationsAdp.ViewHolder> {
    private Context context;
    private List<FoodDetailBean.DataBean.AttrBean> strings;

    public SpecificationsAdp(Context context, List<FoodDetailBean.DataBean.AttrBean> strings) {
        this.context = context;
        this.strings = strings;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.adp_guige, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        if (null != strings && position < strings.size()) {
            holder.tv_content.setText(strings.get(position).getName());
            holder.tv_content.setVisibility(View.VISIBLE);
            holder.img_del.setVisibility(View.VISIBLE);
            holder.img_del.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    if (listener!=null){
//                        strings.remove(position);
//                        notifyDataSetChanged();
//                        listener.showDel(position);
//                    }
                    strings.remove(position);
                    notifyDataSetChanged();
                }
            });
        } else {
            holder.img_del.setVisibility(View.GONE);
            holder.tv_content.setVisibility(View.GONE);
        }
        holder.tv_itemTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener!=null){
                    listener.showAdd();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return strings.size() + 1;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView img_del;
        TextView tv_itemTitle, tv_content;

        public ViewHolder(View itemView) {
            super(itemView);
            img_del = itemView.findViewById(R.id.img_del);
            tv_content = itemView.findViewById(R.id.tv_content);
            tv_itemTitle = itemView.findViewById(R.id.tv_itemTitle);
        }
    }


    public interface getAddType{
        void showAdd();
    }

    public getAddType listener;

    public void setListener(getAddType listener) {
        this.listener = listener;
    }
}
